package org.anti996.bankms.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class IOUtil {
    private static final Scanner scanner_ = new Scanner(System.in);
    // TODO 任何时候，输入Ctrl-C返回上一页

    public static int parseOrder() {
        String input = scanner_.nextLine();
        int result = -1;
        try {
            result = Integer.parseInt(input);
        } catch (NumberFormatException ignored) {}
        return result;
    }

    public static List<Integer> parseOrders() {
        String input = scanner_.nextLine();
        List<Integer> results = new ArrayList<>();
        for (int i = 0; i < input.length(); i++) {
            int c = input.charAt(i) - '0';
            if (0 <= c && c <= 9) {
                results.add(c);
            } else {
                return null;
            }
        }
        return results;
    }

    public static String parseInput() {
        return scanner_.nextLine();
    }

    public static String parsePassword() {
        // TODO 如何把输入密码显示为*
        return scanner_.nextLine();
    }
}
